// ChildFrm.cpp : implementation of the CChildFrame class
//

#include "stdafx.h"
#include "MapEditor.h"

#include "ChildFrm.h"
#include "TilesetView.h"
#include "EditorView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChildFrame

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(CChildFrame)
	ON_COMMAND(ID_LEVEL_0, OnLevel0)
	ON_COMMAND(ID_LEVEL_1, OnLevel1)
	ON_COMMAND(ID_LEVEL_2, OnLevel2)
	ON_COMMAND(ID_LEVEL_3, OnLevel3)
	ON_UPDATE_COMMAND_UI(ID_LEVEL_1, OnUpdateLevel1)
	ON_UPDATE_COMMAND_UI(ID_LEVEL_0, OnUpdateLevel0)
	ON_UPDATE_COMMAND_UI(ID_LEVEL_2, OnUpdateLevel2)
	ON_UPDATE_COMMAND_UI(ID_LEVEL_3, OnUpdateLevel3)
	ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
	ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChildFrame construction/destruction

CChildFrame::CChildFrame()
{
}

CChildFrame::~CChildFrame()
{
}

BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
	CCreateContext* pContext)
{
	// create splitter window
	if (!m_wndSplitter.CreateStatic(this, 1, 2))
		return FALSE;

	if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CTilesetView), CSize(300, 100), pContext) ||
		!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CEditorView), CSize(300, 100), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}

	return TRUE;
}

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CMDIChildWnd::PreCreateWindow(cs) )
		return FALSE;

	cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
		| FWS_ADDTOTITLE | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;

	return TRUE;
}

void CChildFrame::ActivateFrame(int nCmdShow)
{
	nCmdShow = SW_SHOWMAXIMIZED;
	CMDIChildWnd::ActivateFrame(nCmdShow);
}


/////////////////////////////////////////////////////////////////////////////
// CChildFrame diagnostics

#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
	CMDIChildWnd::AssertValid();
}

void CChildFrame::Dump(CDumpContext& dc) const
{
	CMDIChildWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChildFrame message handlers

void CChildFrame::OnLevel0() 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	pView->SetLevel(0);
}

void CChildFrame::OnLevel1() 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	pView->SetLevel(1);
}

void CChildFrame::OnLevel2() 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	pView->SetLevel(2);	
}

void CChildFrame::OnLevel3() 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	pView->SetLevel(3);		
}

void CChildFrame::OnUpdateLevel0(CCmdUI* pCmdUI) 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	int nLevel = pView->GetLevel();
	pCmdUI->SetCheck(nLevel == 0);
}

void CChildFrame::OnUpdateLevel1(CCmdUI* pCmdUI) 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	int nLevel = pView->GetLevel();
	pCmdUI->SetCheck(nLevel == 1);
}


void CChildFrame::OnUpdateLevel2(CCmdUI* pCmdUI) 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	int nLevel = pView->GetLevel();
	pCmdUI->SetCheck(nLevel == 2);
}

void CChildFrame::OnUpdateLevel3(CCmdUI* pCmdUI) 
{
	CEditorView* pView = (CEditorView*)m_wndSplitter.GetPane(0, 1);
	int nLevel = pView->GetLevel();
	pCmdUI->SetCheck(nLevel == 3);
}

void CChildFrame::OnZoomIn() 
{
}

void CChildFrame::OnZoomOut() 
{
}
